package com.ruoyi.user.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.user.domain.Advice;
import com.ruoyi.user.service.IAdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 意见反馈管理Controller
 * 
 * @author fxy
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/advice")
public class AdviceController extends BaseController
{
    @Autowired
    private IAdviceService adviceService;

    /**
     * 查询意见反馈管理列表
     */
    //@RequiresPermissions("user:advice:list")
    @GetMapping("/list")
    public TableDataInfo list(Advice advice)
    {
        startPage();
        List<Advice> list = adviceService.selectAdviceList(advice);
        return getDataTable(list);
    }
    @RequiresPermissions("user:advice:list")
    @GetMapping("/listByNoReply")
    public TableDataInfo listByNoReply(Advice advice)
    {
        startPage();
        List<Advice> list = adviceService.selectAdviceByNoReply(advice);
        return getDataTable(list);
    }

    /**
     * 导出意见反馈管理列表
     */
    @RequiresPermissions("user:advice:export")
    @Log(title = "意见反馈管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Advice advice)
    {
        List<Advice> list = adviceService.selectAdviceList(advice);
        ExcelUtil<Advice> util = new ExcelUtil<Advice>(Advice.class);
        util.exportExcel(response, list, "意见反馈管理数据");
    }

    /**
     * 获取意见反馈管理详细信息
     */
    @RequiresPermissions("user:advice:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adviceService.selectAdviceById(id));
    }

    /**
     * 新增意见反馈管理
     */
    @RequiresPermissions("user:advice:add")
    @Log(title = "意见反馈管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Advice advice)
    {
        return toAjax(adviceService.insertAdvice(advice));
    }

    /**
     * 修改意见反馈管理
     */
    @RequiresPermissions("user:advice:edit")
    @Log(title = "意见反馈管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Advice advice)
    {
        return toAjax(adviceService.updateAdvice(advice));
    }

    /**
     * 删除意见反馈管理
     */
    @RequiresPermissions("user:advice:remove")
    @Log(title = "意见反馈管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adviceService.deleteAdviceByIds(ids));
    }
}
